package com.lyh.web.controller.system;


import com.lyh.common.config.RuoYiConfig;
import com.lyh.common.core.domain.AjaxResult;
import com.lyh.common.exception.file.InvalidExtensionException;
import com.lyh.common.utils.file.FileUploadUtils;
import com.lyh.common.utils.file.MimeTypeUtils;
import com.lyh.system.service.ISysFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Api(value = "文件上传",description = "文件上传-在用")
@RestController
@RequestMapping("/system/file")
public class SysFileController {

    @Autowired
    ISysFileService sysFileService;

    @ApiOperation(value = "图片上传")
    @RequestMapping(value = "/upload/image",method = RequestMethod.POST)
    public AjaxResult fileUploadRefactor(@RequestParam("image") MultipartFile file) throws IOException, InvalidExtensionException {
        String imageUrl = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
        return AjaxResult.success(imageUrl);
    }





}
